package com.example.alibabanacosdiscoveryclient.job;

import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.joda.time.DateTime;

/**
 * @author:guoq
 * @date:2024/10/17
 * @descripion:
 */
@Component
public class SpringJob {
//    /**
//     * 每1s钟跑一次
//     */
//    @Scheduled(cron = "*/1 * * * * ?")
//    @SchedulerLock(name = "SpringJob.job1", lockAtMostFor = "2s", lockAtLeastFor = "1s")
//    public void job1() {
//        System.out.println("time=" + DateTime.now().toString("YYYY-MM-dd HH:mm:ss") + " do job1...");
//    }

    /**
     * 每5秒跑一次
     */
//    @Scheduled(fixedRate = 5000)
//    @SchedulerLock(name = "SpringJob.job2", lockAtMostFor = "4s", lockAtLeastFor = "4s")
//    public void job2() {
//        System.out.println("time=" + DateTime.now().toString("YYYY-MM-dd HH:mm:ss") + " do job2...");
//    }

//    /**
//     * 上次跑完之后隔10秒再跑
//     * @throws InterruptedException
//     */
//    @Scheduled(fixedDelay = 10000)
//    @SchedulerLock(name = "SpringJob.job3", lockAtMostFor = "4s", lockAtLeastFor = "4s")
//    public void job3() throws InterruptedException {
//        System.out.println("time=" + DateTime.now().toString("YYYY-MM-dd HH:mm:ss") + " do job3...");
//        Thread.sleep(10000);
//    }
}
